package generics_and_collections.equals;

/**
 * Created with IntelliJ IDEA.
 * User: Sam
 * Date: 04/02/14
 * Time: 21:17
 * To change this template use File | Settings | File Templates.
 */

import java.util.ArrayList;
import java.util.Collections;

/**
 * pg 569
 */

public class Sorting {

	public Sorting() {
	}

	public void execute() {

		ArrayList<String> stuff = new ArrayList<String>();

		// Objects in List passed to sort(0 must implement Comparible.  String Objects already do. So can be sorted.

		Person a = new Person("Sam", 32, true);
		Person b = new Person("Bruno", 18, true);
		Person c = new Person("Sally", 25, false);

		stuff.add("sam");
		stuff.add("bruno");
		stuff.add("joe");

		//System.out.println(stuff);
		// Sort order is natural order, for Strings this is alphabetical.
		// Sort order is not same thing as order of insertion, access or index.
		//Collections.sort(stuff);
		//System.out.println(stuff);

		stuff.removeAll(stuff);

		ArrayList<Person> people = new ArrayList<Person>();
		people.add(a);
		people.add(b);
		people.add(c);

		// Use our compareTo() implementation
		System.out.println(people);
		Collections.sort(people);
		System.out.println(people);

		Collections.shuffle(people);

		// This time use the other sort() method that takes a Comparator
		System.out.println(people);
		PersonSorter ps = new PersonSorter();
		Collections.sort(people, ps);
		System.out.println(people);
	}
}
